package com.heiye.blog.ai.model.openrouter;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.deepseek.DeepSeekChatOptions;
import org.springframework.ai.model.tool.ToolCallingChatOptions;
import org.springframework.ai.tool.ToolCallback;

import java.util.*;

/**
 * @author: heiye
 * @date: 2025/11/11 下午10:14
 * @version: v1.0.0
 * @description:
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OpenRouterChatOptions implements ToolCallingChatOptions {
    /**
     * 模型名称
     */
    @JsonProperty("model")
    private String model;

    /**
     * 此设置会影响模型响应的多样性。较低的值会导致更可预测和典型的响应，
     * 而较高的值则鼓励更多样化和不太常见的响应。
     * 在 0 时，模型始终对给定输入给出相同的响应。
     * Range: [0, 2]
     */
    @JsonProperty("temperature")
    private Double temperature;

    /**
     * 是否流式返回结果
     */
    @JsonProperty("stream")
    private Boolean stream;

    // 分配多少 token 用于推理
    @JsonProperty("effort")
    String effort;

    // 推理的 token 数量
    @JsonProperty("thank.max_Tokens")
    Integer thankMaxTokens;

    // 是否排除推理结果
    @JsonProperty("exclude")
    Boolean exclude;

    // 是否启用推理
    @JsonProperty("enabled")
    Boolean enable;

    @Override
    public List<ToolCallback> getToolCallbacks() {
        return List.of();
    }

    @Override
    public void setToolCallbacks(List<ToolCallback> toolCallbacks) {

    }

    @Override
    public Set<String> getToolNames() {
        return Set.of();
    }

    @Override
    public void setToolNames(Set<String> toolNames) {

    }

    @Override
    public Boolean getInternalToolExecutionEnabled() {
        return null;
    }

    @Override
    public void setInternalToolExecutionEnabled(Boolean internalToolExecutionEnabled) {

    }

    @Override
    public Map<String, Object> getToolContext() {
        return Map.of();
    }

    @Override
    public void setToolContext(Map<String, Object> toolContext) {

    }
    @Override
    public Double getFrequencyPenalty() {
        return 0.0;
    }

    @Override
    public Integer getMaxTokens() {
        return 0;
    }

    @Override
    public Double getPresencePenalty() {
        return 0.0;
    }

    @Override
    public List<String> getStopSequences() {
        return List.of();
    }
    @Override
    public Integer getTopK() {
        return 0;
    }

    @Override
    public Double getTopP() {
        return 0.0;
    }

    @Override
    public OpenRouterChatOptions copy() {
        return fromOptions(this);
    }

    public static OpenRouterChatOptions fromOptions(OpenRouterChatOptions fromOptions) {
        return builder()
                .model(fromOptions.getModel())
//                .frequencyPenalty(fromOptions.getFrequencyPenalty())
//                .logprobs(fromOptions.getLogprobs())
//                .topLogprobs(fromOptions.getTopLogprobs())
//                .maxTokens(fromOptions.getMaxTokens())
//                .presencePenalty(fromOptions.getPresencePenalty())
//                .responseFormat(fromOptions.getResponseFormat())
//                .stop(fromOptions.getStop() != null ? new ArrayList(fromOptions.getStop()) : null)
                .temperature(fromOptions.getTemperature())
                .effort(fromOptions.getEffort())
                .thankMaxTokens(fromOptions.getThankMaxTokens())
                .exclude(fromOptions.getExclude())
                .enable(fromOptions.getEnable())
//                .topP(fromOptions.getTopP())
//                .tools(fromOptions.getTools())
//                .toolChoice(fromOptions.getToolChoice())
//                .toolCallbacks((List)(fromOptions.getToolCallbacks() != null ? new ArrayList(fromOptions.getToolCallbacks()) : null))
//                .toolNames((Set)(fromOptions.getToolNames() != null ? new HashSet(fromOptions.getToolNames()) : null))
//                .internalToolExecutionEnabled(fromOptions.getInternalToolExecutionEnabled())
//                .toolContext(fromOptions.getToolContext() != null ? new HashMap(fromOptions.getToolContext()) : null)
                .build();
    }
}
